﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;

namespace FigKey_TestExec_SL.Controls
{
    /// <summary>
    /// 重绘Group Box，突出边框部分，并自定义颜色
    /// </summary>
    public partial class FGroupBox : GroupBox
    {
        [Browsable(true), Description("边框颜色"), Category("自定义分组")]
        public Color BorderColor { get; set; } = Color.DarkGray;

        public FGroupBox()
        {
            InitializeComponent();
        }

        public FGroupBox(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            var vSize = e.Graphics.MeasureString(this.Text, this.Font);

            e.Graphics.Clear(this.BackColor);
            e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), 10, 1);

            Pen pen = new Pen(this.BorderColor);
            e.Graphics.DrawLine(pen, 1, vSize.Height / 2, 8, vSize.Height / 2);
            e.Graphics.DrawLine(pen, vSize.Width + 8, vSize.Height / 2, this.Width - 2, vSize.Height / 2);
            e.Graphics.DrawLine(pen, 1, vSize.Height / 2, 1, this.Height - 2);
            e.Graphics.DrawLine(pen, 1, this.Height - 2, this.Width - 2, this.Height - 2);
            e.Graphics.DrawLine(pen, this.Width - 2, vSize.Height / 2, this.Width - 2, this.Height - 2);
        }
    }
}
